//
// Created by 24994 on 2021/10/5.
//
#include "playGame.h"
#include <stdio.h>
#include <stdlib.h>
#include "InputHelper.h"

void playGame(int role)
{
    printf("game action\n");
    extern int sunWuKongHP;
    extern int sunWuKongSkills[2];
    extern char sunWuKongSkillsName[][20];

    extern int baiGuJinHP;
    extern int baiGuJinSkills[2];
    extern char baiGuJinSkillsName[][20];

    int randomNum = 0; // 电脑控制的人物释放技能的随机数

    while (sunWuKongHP>=0 && baiGuJinHP >=0){
        printf("BaiGuJin begin attack now\n");
        // 白骨精发起攻击
        // 展示白骨精的技能
        for(int i=0;i<3;i++){
            printf("%d[%s]\n",i,baiGuJinSkillsName[i]);
        }
        // 手动释放技能
        int killNum = inputNum("please choose your skill\n");
        printf("BaiGuJin use a GongFu %s\n",baiGuJinSkillsName[killNum]);
        int useKill =  baiGuJinSkills[killNum];
        // 孙悟空掉血
        sunWuKongHP = sunWuKongHP -useKill;
        printf("SunWuKong shout you hurt me HP-%d,SunWuKong has HP %d\n",useKill,sunWuKongHP);
        printf("--------------------------------------------------------\n");
        // 孙悟空发动攻击
        printf("SunWuKong begin attack now\n");
        // 生成一个随机数来确定孙悟空释放的技能
        randomNum = rand()%2;
        printf("SunWuKong use a GongFu%s\n",sunWuKongSkillsName[randomNum]);
        int pcUseKill = sunWuKongSkills[randomNum]; // 孙悟空的攻击值
        baiGuJinHP = baiGuJinHP -pcUseKill;
        printf("BaiGuJin shout you hurt me HP-%d,BaiGuJin has HP %d\n",pcUseKill,baiGuJinHP);
    }
    printf("------------------------------------------------\n");
    printf("game over\n");
    if(sunWuKongHP<=0 && baiGuJinHP>0){
        printf("BaiGuJin win\n");
    }
    if(baiGuJinHP<=0 && sunWuKongHP>0){
        printf("SunWuKong win\n");
    }
}

